package com.czxy.changgou3.com.czxy.changgou3.controller;

import com.czxy.changgou3.com.czxy.changgou3.service.SpecificationService;
import com.czxy.changgou3.pojo.Specification;
import com.czxy.vo.BaseResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zhangmengxiang1@itcast.cn
 * @version 1.0
 * @date 2020/4/22
 */
@RestController
@RequestMapping("/specifications")
public class SpecificationController {

    @Resource
    private SpecificationService specificationService;

    /** 查询指定分类的所有规格
     * /specifications/category/76
     * @param categoryId
     * @return
     */
    @GetMapping("/category/{categoryId}")
    public BaseResult findAll(@PathVariable("categoryId") Integer categoryId ){
        // 判断
        if(categoryId == null) {
            return BaseResult.error("查询规格失败");
        }
        // 查询
        List<Specification> list = specificationService.findAll(categoryId);
        // 返回
        return BaseResult.ok("查询成功", list );
    }
}
